package com.chat.datea.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.chat.datea.fragment.MusicPlaylistFragment;
import com.chat.datea.fragment.MusicRankingFragment;
import com.chat.datea.fragment.MusicRecomFragment;
import com.chat.datea.fragment.SingerFragment;

import java.util.ArrayList;

/**
 * Created by xyb on 15/10/20.
 */
public class MusicClubFragment_ViewPager_Adapter extends FragmentPagerAdapter {
    private ArrayList<Fragment> fragments;
    private String [] title = {"推荐","歌手","排行","歌单"};
    private FragmentManager fManager;

    public MusicClubFragment_ViewPager_Adapter(FragmentManager fm,FragmentManager chl) {
        super(chl);
        this.fManager = fm;
        initData();
    }

    private void initData() {
        fragments = new ArrayList<>();
        fragments.add(new MusicRecomFragment(fManager));
        fragments.add(new SingerFragment());
        fragments.add(new MusicRankingFragment());
        fragments.add(new MusicPlaylistFragment());
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.size() > 0 && fragments != null ? fragments.get(position) : null;
    }

    @Override
    public int getCount() {
        return fragments.size() > 0 && fragments != null ? fragments.size() : 0;
    }
    @Override
    public CharSequence getPageTitle(int position) {
        return title[position];
    }

}
